<?php

class CoreDbRedis extends CoreInstance
{
    protected ?Redis $redis_instance = null;
    public function getRedis(): Redis
    {
        // TODO: Implement instance() method.
        $config = IniReaderRedis::getConfig('redis.memory', 'common');

        // TODO: Implement getInstance() method.
        $this->redis_instance = new \Redis();
        $this->redis_instance->connect($config->host, $config->port);
        $this->redis_instance->auth($config->password);

        return $this->redis_instance;
    }

    public function __destruct()
    {
        $this->close();
    }

    final public function close()
    {
        $this->redis_instance?->close();
    }
}